package bootstrap

import (
	"github.com/kataras/golog"
	"nprobe/enviroments"
	"os"
	"path/filepath"
)

// InitEnv 初始化全局环境变量
func InitEnv() error {
	var err error
	exe, err := os.Executable()
	if err != nil {
		golog.Errorf("os.Executable() failed. err: %+v", err)
		return err
	}
	enviroments.ExeDir = filepath.Dir(exe)
	enviroments.WorkDir, err = os.Getwd()
	if err != nil {
		golog.Errorf("os.Getwd() failed. err: %+v", err)
		return err
	}
	enviroments.PID = os.Getpid()
	enviroments.Hostname, err = os.Hostname()
	if err != nil {
		golog.Errorf("os.Hostname() failed. err: %+v", err)
		return err
	}
	return nil
}
